var Calendar = {
	clickDayTime : null,
	obj : null,
	initCalendar : function() {
		var thiz = this;
		if (this.obj == null) {
			console.error('error', 'Calendar.obj is not defined')
		} else {
			this.obj.fullCalendar({
				header : {
					left : 'prev,next today',
					center : 'title',
					right : 'month,agendaWeek,agendaDay',
					today:    'today'
				},
				contentHeight : document.documentElement.clientHeight*0.8,
				dayClick : this.initDayClick,
				eventMouseover : this.intiEventMouseover,
				eventMouseout : this.initEventMouseout,
//				timezone : 'Asia/Shanghai',
//				timezone: 'America/Chicago',
				lang : 'zh-cn',
				eventLimit : 2, // allow "more" link when too many events
				events : function(start, end, timezone, callback) {
					$.ajax({
						type : 'POST',
						url : base+'/note/map.action',
						dataType : 'JSON',
						success : function(res) {
							callback(res.data);
						},
						error : function() {
						}
					})
				},
                editable : false,
				selectable: true,
				selectHelper: true,
                select : function(start, end) {
            	    Calendar.clickDayTimeStart = start;
            	    Calendar.clickDayTimeEnd = end;
            	    console.info(start.valueOf())
                	$("#formDiv").load("noteForm.jsp",function(){
                	   $("#noteModal").modal('show');
                	});
//                	var title = "noteModal"
//                    var eventData;
//                    if (title) {
//                        eventData = {
//                            title: title,
//                            start: start,
//                            end: end,
//                            allDay:false
//                        };
//                        thiz.obj.fullCalendar('renderEvent', eventData, true); // stick? = true
//                    }
//                    thiz.obj.fullCalendar('unselect');
                },
                eventClick: function(calEvent, jsEvent, view) {

//                    alert('Event: ' + calEvent.title);
//                    alert('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY);
//                    alert('View: ' + view.name);
            
                    // change the border color just for fun
//                    $(this).css('border-color', 'red');
            
                }
				
			});
		}
	},
	tody : function() {
		$("#noteModal").modal('toggle');
//		console.info($.fullCalendar.formatRange)
//		this.obj.fullCalendar('today');
	},
	initDayClick : function(date, jsEvent, view) {
//		console.info('Clicked on: ' + date.format());
//		console.info('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY);
//		console.info('Current view: ' + view.name);
		// change the day's background color just for fun
//		$(this).css('background-color', '#D44343');

	},
	intiEventMouseover : function(event, jsEvent, view) {
		$(this).css('background-color', '#D44343');
		Calendar.createbubble(event, jsEvent, view);
	},
	initEventMouseout : function(event, jsEvent, view) {
		$(this).css('background-color', '#3A87AD');
		Calendar.destorybubble();
	},
	createbubble : function(event, jsEvent, view){
		var title = event.title;
		Calendar.bubble = $("<div class='bubbleCss'>"+title+"</div>");
		Calendar.bubble.css("left",jsEvent.pageX)
		Calendar.bubble.css("top",jsEvent.pageY)
		Calendar.bubble.fadeIn({duration:800},function(){
			
		});
		$("body").append(Calendar.bubble);
	},
	destorybubble : function(){
		Calendar.bubble.fadeOut({duration:800},function(){
			Calendar.bubble.remove();
		});
	}
};
$(document).ready(function() {
	Calendar.obj = $('#calendar');
	Calendar.initCalendar();
});
